package hadoop.mapreduce.partition;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;


public class PhoneMapper extends Mapper <LongWritable, Text,Text,PhoneBean>{
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String string = value.toString();
        String[] split = string.split("\t");
        String phoneNum = split[1];
        long upFlow = Long.parseLong(split[split.length - 3]);
        long downFlow = Long.parseLong(split[split.length - 2]);

        PhoneBean phoneBean = new PhoneBean();
        phoneBean.setUpFlow(upFlow);
        phoneBean.setDownFlow(downFlow);
        phoneBean.setSumFlow(upFlow+downFlow);

        context.write(new Text(phoneNum),phoneBean);
        // key         value
        //{13736230513,phoneBean{2481,24681,27162}}
    }
}
